clear all
macro drop _all
set more off
set type double

use hwol_edu.dta

rename geography code

egen county_edu_fe = group(code educationcode)
egen county_time_fe = group(code date)
egen time_edu_fe = group(date educationcode)

sort county_edu_fe date
xtset county_edu_fe date

gen state_code = real(substr(string(code,"%05.0f"),1,2))

gen ln_vol = ln(volume_sum)
gen ln_volnew = ln(volumenew_sum)
gen inv_hysine = ln(volume + sqrt(volume^2 +1))

/*drop DE from the dataset all-together */
drop if state_code==10
/* ban  = 1 for states after they pass the ban, only for non-exempt occupations */
gen ban = 0

replace ban= 1 if (state_code==06 & date>=tq(2012q1)) | ///
(state_code==08 & date>=tq(2013q3)) | (state_code==09 & date>=tq(2011q4)) | ///
(state_code==10 & date>=tq(2014q2)) | (state_code==15 & date>=tq(2009q3)) | ///
(state_code==17 & date>=tq(2011q1)) | (state_code==24 & date>=tq(2011q4)) | ///
(state_code==32 & date>=tq(2013q4)) | (state_code==41 & date>=tq(2010q2)) | ///
(state_code==50 & date>=tq(2012q3)) | (state_code==53 & date>=tq(2007q3))

// Ban duration dummies
gen ban_duration_0 = 0

//For first obs where county gets ban
replace ban_duration_0= 1 if (state_code==06 & date==tq(2012q1)) | ///
(state_code==08 & date==tq(2013q3)) | (state_code==09 & date==tq(2011q4)) | ///
(state_code==10 & date==tq(2014q2)) | (state_code==15 & date==tq(2009q3)) | ///
(state_code==17 & date==tq(2011q1)) | (state_code==24 & date==tq(2011q4)) | ///
(state_code==32 & date==tq(2013q4)) | (state_code==41 & date==tq(2010q2)) | ///
(state_code==50 & date==tq(2012q3)) | (state_code==53 & date==tq(2007q3))

gen ban_duration_1 = 0 
//For quarter+1 from when the law was passed
replace ban_duration_1 = 1 if l.ban_duration_0==1

gen ban_duration_2 = 0 
//For quarter+2
replace ban_duration_2 = 1 if l.ban_duration_1==1

gen ban_duration_3 = 0
replace ban_duration_3 = 1 if l.ban_duration_2==1

gen ban_duration_4 = 0
replace ban_duration_4 = 1 if l.ban_duration_3==1

gen ban_duration_5 = 0 
//For all further observations (passed the first year)
replace ban_duration_5 = 1 if l.ban_duration_4==1
replace ban_duration_5 = l.ban_duration_5 if ban_duration_5==0 & l.ban_duration_5==1

//Now same thing counting backwards, count back four quarters
//Previous 4 quaters 

gen ban_duration_neg1 = 0
replace ban_duration_neg1 = 1 if f.ban_duration_0==1

gen ban_duration_neg2 = 0
replace ban_duration_neg2 = 1 if f.ban_duration_neg1==1

gen ban_duration_neg3 = 0
replace ban_duration_neg3 = 1 if f.ban_duration_neg2==1

gen ban_duration_neg4 = 0
replace ban_duration_neg4 = 1 if f.ban_duration_neg3==1

* Education Varianles
*1	Less than high school
*2	Doctoral or professional degree
*3	Master's degree
*4	Some college, no degree
*5	Bachelor's degree
*6	Associate's degree
*7	Postsecondary nondegree award
*8	High school diploma or equivalent

* Low Skill 1, 8 (1, 8 and 7)
* Med Skill 4, 6 and 7  (5 and 6)
* High Skill 5, 2, and 3 (only 2 and 3)

gen low_skill = 0
replace low_skill = 1 if (educationcode == 1 | educationcode == 8)

gen low_skill_ban = ban*low_skill

* Column 2 of Table A6
reghdfe inv_hysine low_skill_ban , absorb(county_edu_fe county_time_fe time_edu_fe) vce(cluster state_code educationcode )
outreg2 using table_A6.xls, dec(3) append

gen low_skill_ban_dur_0 = low_skill*ban_duration_0
gen low_skill_ban_dur_1 = low_skill*ban_duration_1
gen low_skill_ban_dur_2 = low_skill*ban_duration_2
gen low_skill_ban_dur_3 = low_skill*ban_duration_3
gen low_skill_ban_dur_4 = low_skill*ban_duration_4
gen low_skill_ban_dur_5 = low_skill*ban_duration_5

gen low_skill_ban_dur_neg1 = low_skill*ban_duration_neg1
gen low_skill_ban_dur_neg2 = low_skill*ban_duration_neg2
gen low_skill_ban_dur_neg3 = low_skill*ban_duration_neg3
gen low_skill_ban_dur_neg4 = low_skill*ban_duration_neg4

* Column 3 of Table A5
reghdfe inv_hysine low_skill_ban_dur_neg4 low_skill_ban_dur_neg3 ///
low_skill_ban_dur_neg2 low_skill_ban_dur_neg1 low_skill_ban_dur_0 /// 
low_skill_ban_dur_1 low_skill_ban_dur_2 low_skill_ban_dur_3 ///
low_skill_ban_dur_4 low_skill_ban_dur_5 ///
, absorb(county_edu_fe county_time_fe time_edu_fe) vce(cluster state_code educationcode)
outreg2 using table_A5.xls, dec(3) append


